package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.business.dao.inter.DonationItemDao;
import com.yunfeisoft.business.model.DonationItem;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * ClassName: DonationItemDaoImpl
 * Description: 捐赠物品详细Dao实现
 * Author: Jackie liu
 * Date: 2020-05-14
 */
@Repository
public class DonationItemDaoImpl extends BaseDaoImpl<DonationItem, String> implements DonationItemDao {

    @Override
    public Page<DonationItem> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            initPageParam(wb, params);
        }
        return queryPage(wb);
    }

    @Override
    public int deleteByDonationId(String donationId) {
        String sql = String.format("DELETE FROM %s WHERE DONATION_ID_ = ?", domainModel.getTableName());
        return jdbcTemplate.update(sql, donationId);
    }

    @Override
    public List<DonationItem> queryByDonationId(String donationId) {
        if (StringUtils.isBlank(donationId)) {
            return new ArrayList<>();
        }

        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("donationId", donationId);
        return query(wb);
    }
}